#include "link.h"

//创建头节点
Pliink create()
{
	Pliink p=malloc(sizeof(liink));
	if(p==NULL)
	{
		printf("创建失败\n");
		return NULL;
	}
	p->len=0;
	p->next=NULL;
	printf("创建成功\n");
	return p;
}
//入栈
int push(Pliink p,int e)
{
	if(p==NULL)
	{
		printf("入栈失败\n");
		return -1;
	}
	student *t=malloc(sizeof(student));
	t->data=e;
	t->next=p->next;
	p->next=t;
	p->len++;
	printf("入栈成功\n");
	return 0;
}
//出栈
int pop(Pliink p)
{
	if(p==NULL || p->next==NULL || p->len<0)
	{
		printf("出栈失败\n");
		return -1;
	}
	student *t=p->next;
	p->next=t->next;
	printf("下标为%d的链栈数据为：%d\n",p->len,t->data);
	free(t);
	t=NULL;
	p->len--;
	return 0;
}
//遍历输出
int put(Pliink p)
{
	if(p==NULL || p->len<0 || p->next==NULL)
	{
		printf("链栈异常\n");
		return -1;
	}
	student *t=p->next;
	while(t!=NULL)
	{
		printf("遍历输出:%d\n",t->data);
		t=t->next;
	}
	return 0;
		
}
